Retrieving Data to XML

Description

Create an SQL::Connection object, select data from a server, and convert it to XML.

You can select data from a server and convert it to XML. First, create a SQL::Connection object.

dim conn as SQL::Connection
dim data as C
dim qry as C
qry = "SELECT * FROM customers"

Open the connection. In the example below, we are using the AADemo-Northwind connection string, which can be created from the AlphaDAO Connections dialog in Alpha Anywhere.

? conn.open("::Name::AADemo-Northwind")
= .T.

Get the data. The [SQL::Connection toXML] function will retrieve the query results and format them as an XML object.

data = conn.ToXML(qry)

The first few lines of the generated XML along with the first record are shown below:

? data
=<DOCUMENT>
	<ROW>
		<CustomerID>ALFKI</CustomerID>
		<CompanyName>Alfreds Futterkiste</CompanyName>
		<ContactName>Maria Anders</ContactName>
		<ContactTitle>Sales Representative</ContactTitle>
		<Address>Obere Str. 57</Address>
		<City>Berlin</City>
		<Region></Region>
		<PostalCode>12209</PostalCode>
		<Country>Germany</Country>
		<Phone>030-0074321</Phone>
		<Fax>030-0076545</Fax>
		<Image></Image>
		<ImageThumbnail></ImageThumbnail>
	</ROW>
...

After data has been retrieved, close the connection.

conn.close()

See Also